<?php

//<editor-fold defaultstate="collapsed" desc="License & Copyright">
/*
 * @license
 */

/**
 *
 * @author Jevgeni Geimanen (jevgeni.geimanen@gmail.com)
 */
//</editor-fold>
class SCContainer extends Component {

    /**
     *
     * @var ComponentCollection
     */
    protected $_ChildControls;

    /**
     *
     * @return ComponentCollection 
     */
    public function getChildControls() {
        if ($this->_ChildControls === null) {
            $this->_ChildControls = new ComponentCollection();
        }
        $this->_ChildControls->setParentControl($this);
        return $this->_ChildControls;
    }

    /**
     *
     * @param Component $control
     * @return Component
     */
    public function AddChildControl($control) {
        return $this->getChildControls()->Add($control);
    }

    /**
     *
     * @return Component 
     */
    public function Init() {
        parent::Init();
        return $this;
    }

    /**
     *
     * @return Component 
     */
    public function Create() {
        $this->getChildControls()->Create();
        return parent::Create();
    }

    /**
     *
     * @return Component 
     */
    public function DispatchEvents() {
        parent::DispatchEvents();
        foreach ($this->getChildControls() as $uid => $control)
            $control->DispatchEvents();
        return $this;
    }

    
    /**
     *
     * @return Container
     */
    public function CollectJSProperties(&$collection) {
        $collection['children'] = array();
        foreach ($this->getChildControls() as $control) {
            $collection['children'][$control->getControlName()] = $control->getJSProperties();
        }
        return parent::CollectJSProperties($collection);
    }

}

?>
